package com.multithreading;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @author chenqb
 * @version 1.0
 * @description:
 * @date 2022/1/4 17:45
 */
public class AtomicLongTest {
    private static AtomicLong atomicLong = new AtomicLong();


    private static Integer[] arrayOne = new Integer[]{0, 1, 2, 3, 0, 5, 6, 0, 56, 0};
    private static Integer[] arrayTwo = new Integer[]{10, 1, 2, 3, 0, 5, 6, 0, 56, 0};

    public static void main(String[] args) throws InterruptedException {
      Thread oneThread =  new Thread(new Runnable() {
            @Override
            public void run() {
                int size =arrayOne.length;
                for (int i = 0; i < size; i++) {
                    if (arrayOne[i].intValue() == 0 ){
                        atomicLong.incrementAndGet();
                    }
                }
            }
        });

        Thread twoThread =  new Thread(new Runnable() {
            @Override
            public void run() {
                int size =arrayTwo.length;
                for (int i = 0; i < size; i++) {
                    if (arrayTwo[i].intValue() == 0 ){
                        atomicLong.incrementAndGet();
                    }
                }
            }
        });

        oneThread.start();
        twoThread.start();

        oneThread.join();
        twoThread.join();

        System.out.println("count 0:"+atomicLong.get());

    }


}
